package com.zxq.web.head.controller;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.zxq.common.controller.BaseController;
import com.zxq.common.pojo.ApiResponse;
import com.zxq.common.pojo.ApiResponseEnum;
import com.zxq.common.util.ConstatFinalUtil;
import com.zxq.common.util.PageInfoUtil;
import com.zxq.lawenf.pojo.AApproval;
import com.zxq.lawenf.pojo.ACase;
import com.zxq.lawenf.pojo.ACaseEnum;
import com.zxq.lawenf.pojo.ACate;
import com.zxq.lawenf.pojo.ACateEnum;
import com.zxq.lawenf.pojo.AHistory;
import com.zxq.lawenf.service.ILawEnfDbService;
import com.zxq.users.pojo.AUsers;
import com.zxq.users.pojo.AUsersEnum;
import com.zxq.users.service.IUsersOperService;

/**
 * 用户首页操作
 * 
 * @author wangsh
 */
@Controller
@RequestMapping("/head/lawEnf")
public class LawEnfHeadControlelr extends BaseController
{
	@Resource
	private ILawEnfDbService lawEnfDbService;
	
	@Resource
	private IUsersOperService usersOperService;
	
	/*====申请单表开始====*/
	/**
	 * 申请单列表页面
	 * @return
	 */
	@RequestMapping("/approvalList")
	public String approvalList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalList--");
		/* 当前用户 */
		AUsers users = (AUsers) this.findObjfromSession(request, "users");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/*---- 额外增加的新条件 ----*/
		/*---- usersId ----*/
		condMap.put("usersId", users.getId());
		
		/*---- appType ----*/
		String appType = request.getParameter("appType");
		if(appType == null)
		{
			appType = "";
		}
		condMap.put("appType", appType);
		request.setAttribute("appType", appType);
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<AApproval> apiResponse = this.lawEnfDbService.findCondListApprovalService(pageInfoUtil, condMap);
		/* 清除提示信息 */
		apiResponse.clearInfo();
		/* 将结果存储到Request中 */
		request.setAttribute("response", apiResponse.toJSON());
		return "/head/lawEnf/approvalList";
	}

	/**
	 * 打开添加申请单页面
	 * @return
	 */
	@RequestMapping("/approvalInsert")
	public String approvalInsert(HttpServletRequest request,String updateFlag,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalInsert--");
		/* 查询所有的模板数据 */
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("cateType", ACateEnum.CATETYPE_APPROVAL.getStatus() + "");
		condMap.put("status", ACateEnum.STATUS_ENABLE.getStatus() + "");
		/* 查询所有的数据 */
		ApiResponse<ACate> cateApiResponse = this.lawEnfDbService.findCondListCateService(null, condMap);
		if(updateFlag == null || "".equalsIgnoreCase(updateFlag))
		{
			/* 清除信息 */
			cateApiResponse.clearInfo();
		}
		/* 保存数据 */
		request.setAttribute("cateList", cateApiResponse.toJSON());
		return "/head/lawEnf/approvalInsert";
	}
	
	/**
	 * 添加申请单提交操作
	 * @return
	 */
	@RequestMapping("/approvalInsertSubmit")
	public String approvalInsertSubmit(HttpServletRequest request, String pubTimeStr , AApproval approval, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalInsertSubmit--");
		/* 当前用户 */
		AUsers users = (AUsers) this.findObjfromSession(request, "users");
		/* 设置用户Id */
		approval.setUsersId(users.getId() ) ;
		
		/* 为对象赋值 */
		approval.setPubTime(new Date());
		approval.setCreateTime(new Date());
		approval.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.lawEnfDbService.saveOneApprovalService(approval);
		ConstatFinalUtil.SYS_LOGGER.info("--申请单添加返回结果:{}--",response.toJSON());
		request.setAttribute("response", response.toJSON());
		return  this.approvalInsert(request,this.cleanInfoFlag, model);
	}
	
	/**
	 * 打开更新申请单页面
	 * @return
	 */
	@RequestMapping("/approvalUpdate")
	public String approvalUpdate(HttpServletRequest request,String id,String updateFlag,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<AApproval> apiResponse = this.lawEnfDbService.findOneApprovalService(condMap);
		if(updateFlag == null || "".equalsIgnoreCase(updateFlag))
		{
			/* 清除信息 */
			apiResponse.clearInfo();
		}
		/* 保留原来的信息 */
		JSONObject responseJSON = this.souResponse(request, apiResponse.toJSON());
		request.setAttribute("response", responseJSON);
		/* 存储request */
		
		/* 准备查询条件 */
		condMap.clear();
		condMap.put("cateType", ACateEnum.CATETYPE_APPROVAL.getStatus() + "");
		condMap.put("status", ACateEnum.STATUS_ENABLE.getStatus() + "");
		/* 查询所有的数据 */
		ApiResponse<ACate> cateApiResponse = this.lawEnfDbService.findCondListCateService(null, condMap);
		if(updateFlag == null || "".equalsIgnoreCase(updateFlag))
		{
			/* 清除信息 */
			cateApiResponse.clearInfo();
		}
		/* 保存数据 */
		request.setAttribute("cateList", cateApiResponse.toJSON());
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			return "/head/lawEnf/approvalUpdate";
		}
		return "/head/lawEnf/approvalInfo";
	}
	
	/**
	 * 添加申请单提交操作
	 * @return
	 */
	@RequestMapping("/approvalUpdateSubmit")
	public String approvalUpdateSubmit(HttpServletRequest request,String id,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalUpdateSubmit--");
		ApiResponse<Object> apiResponseRes = new ApiResponse<Object>();
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<AApproval> response = this.lawEnfDbService.findOneApprovalService(condMap);
		/* 获取java对象 */
		AApproval approval = response.getDataOneJava() ;
		
		String operType = request.getParameter("operType");
		if("update".equalsIgnoreCase(operType))
		{
			/* 接收参数 */
			String name = request.getParameter("name");
			String appType = request.getParameter("appType");
			String content = request.getParameter("content");
			String status = request.getParameter("status");
			
			/* 设置属性 */
			approval.setName(name);
			approval.setAppType(Byte.valueOf(appType));
			approval.setContent(content);
			approval.setStatus(Byte.valueOf(status));
			
			approval.setUpdateTime(new Date());
			/* 数据库操作 */
			ApiResponse dbRes = this.lawEnfDbService.updateOneApprovalService(approval);
			ConstatFinalUtil.SYS_LOGGER.info("--申请单添加返回结果:{}--",dbRes.toJSON());
			request.setAttribute("response", dbRes.toJSON());
		}
		return approvalUpdate(request, id, this.cleanInfoFlag, model);
	}
	
	/**
	 * 申请单批量操作
	 * @return
	 */
	@RequestMapping(value = "/approvalBatch" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String approvalBatch(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");
		
		/* 操作类型 */
		String operType = request.getParameter("operType");
		if(ids != null)
		{
			int totalNum = ids.length ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");
					
					condMap.clear();
					condMap.put("id", id);
					ApiResponse<AApproval> apiResponseDb = this.lawEnfDbService.findOneApprovalService(condMap);
					AApproval approval = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					approval.setStatus(Byte.valueOf(status));
					approval.setPubTime(new Date());
					
					ApiResponse<Object> approvalClassResponse = this.lawEnfDbService.updateOneApprovalService(approval);
					if(approvalClassResponse.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 
					}else
					{
						failedNum ++ ; 
					}
				}
			}
			
			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		return apiResponse.toJSON().toJSONString();
	}
	/*====申请单表结束====*/
	
	/*====案件表开始====*/
	/**
	 * 案件列表页面
	 * @return
	 */
	@RequestMapping("/caseList")
	public String caseList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--caseList--");
		/* 当前用户 */
		AUsers users = (AUsers) this.findObjfromSession(request, "users");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/*---- 额外增加的新条件 ----*/
		/*---- appType ----*/
		String appType = request.getParameter("appType");
		if(appType == null)
		{
			appType = "";
		}
		condMap.put("appType", appType);
		request.setAttribute("appType", appType);
		
		String operType = request.getParameter("operType");
		request.setAttribute("operType", operType);
		if("self".equalsIgnoreCase(operType))
		{
			/* 我发起的 */
			/*---- usersId ----*/
			condMap.put("usersId", users.getId());
		}else if("pending".equalsIgnoreCase(operType))
		{
			/* 待处理,需要处理上级发的 */
			Map<String, Object> extMap = new HashMap<String, Object>();
			/* 上级 */
			extMap.put("operType", AUsersEnum.OPERTYPE_TREE_UP.getStatus());
			//condMap.put("operType", AUsersEnum.OPERTYPE_TREE_UP.getStatus());
			/* 用户Id */
			extMap.put("usersId", users.getId());
			
			/* 查询用户上级关系 */
			List<AUsers> usersList = this.usersOperService.findCondListTreeUsersService(extMap);
			
			List<String> usersIdList = new ArrayList<String>();
			for (Iterator iterator = usersList.iterator(); iterator.hasNext();)
			{
				AUsers usersTemp = (AUsers) iterator.next();
				usersIdList.add(usersTemp.getId() + "");
			}
			
			/* 用户列表 */
			condMap.put("usersIdList", usersIdList);
			if(usersIdList.size() == 0)
			{
				return "/head/lawEnf/caseList";
			}
		}else if("audit".equalsIgnoreCase(operType))
		{
			/* 待审核下级,需要审核下级发的 */
			Map<String, Object> extMap = new HashMap<String, Object>();
			extMap.put("operType", AUsersEnum.OPERTYPE_TREE_DOWN.getStatus());
			//condMap.put("operType", AUsersEnum.OPERTYPE_TREE_UP.getStatus());
			/* 用户Id */
			extMap.put("usersId",  users.getId());
			
			/* 查询用户上级关系 */
			List<AUsers> usersList = this.usersOperService.findCondListTreeUsersService(extMap);
			List<String> usersIdList = new ArrayList<String>();
			for (Iterator iterator = usersList.iterator(); iterator.hasNext();)
			{
				AUsers usersTemp = (AUsers) iterator.next();
				usersIdList.add(usersTemp.getId() + "");
			}
			
			/* 用户列表 */
			condMap.put("usersIdList", usersIdList);
			if(usersIdList.size() == 0)
			{
				return "/head/lawEnf/caseList";
			}
		}else if("import".equalsIgnoreCase(operType))
		{
			/* 待审核下级,需要审核下级发的 */
			Map<String, Object> extMap = new HashMap<String, Object>();
			extMap.put("operType", AUsersEnum.OPERTYPE_TREE_DOWN.getStatus());
			//condMap.put("operType", AUsersEnum.OPERTYPE_TREE_UP.getStatus());
			/* 用户Id */
			extMap.put("usersId",  users.getId());
			
			/* 查询用户上级关系 */
			List<AUsers> usersList = this.usersOperService.findCondListTreeUsersService(extMap);
			List<String> usersIdList = new ArrayList<String>();
			for (Iterator iterator = usersList.iterator(); iterator.hasNext();)
			{
				AUsers usersTemp = (AUsers) iterator.next();
				usersIdList.add(usersTemp.getId() + "");
			}
			
			/* 用户列表 */
			condMap.put("depUseIdList", usersIdList);
			if(usersIdList.size() == 0)
			{
				return "/head/lawEnf/caseList";
			}
			/* 必须是重大案件 */
			condMap.put("appType", ACaseEnum.APPTYPE_IMPORT.getStatus());
		}else if("depart".equalsIgnoreCase(operType))
		{
			/* 待审核下级,需要审核下级发的 */
			Map<String, Object> extMap = new HashMap<String, Object>();
			//condMap.put("operType", AUsersEnum.OPERTYPE_TREE_UP.getStatus());
			/* 用户Id */
			extMap.put("usersId",  users.getId());
			
			/* 查询用户上级关系 */
			List<AUsers> usersList = this.usersOperService.findCondListDepartUsersService(extMap);
			List<String> usersIdList = new ArrayList<String>();
			for (Iterator iterator = usersList.iterator(); iterator.hasNext();)
			{
				AUsers usersTemp = (AUsers) iterator.next();
				usersIdList.add(usersTemp.getId() + "");
			}
			
			/* 用户列表 */
			condMap.put("usersIdList", usersIdList);
			if(usersIdList.size() == 0)
			{
				return "/head/lawEnf/caseList";
			}
		}
		
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<ACase> apiResponse = this.lawEnfDbService.findCondListCaseService(pageInfoUtil, condMap);
		/* 清除提示信息 */
		apiResponse.clearInfo();
		/* 将结果存储到Request中 */
		request.setAttribute("response", apiResponse.toJSON());
		return "/head/lawEnf/caseList";
	}

	/**
	 * 打开添加案件页面
	 * @return
	 */
	@RequestMapping("/caseInsert")
	public String caseInsert(HttpServletRequest request,String updateFlag,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--caseInsert--");
		/* 查询所有的模板数据 */
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("cateType", ACateEnum.CATETYPE_CASE.getStatus() + "");
		condMap.put("status", ACateEnum.STATUS_ENABLE.getStatus() + "");
		/* 查询所有的数据 */
		ApiResponse<ACate> cateApiResponse = this.lawEnfDbService.findCondListCateService(null, condMap);
		if(updateFlag == null || "".equalsIgnoreCase(updateFlag))
		{
			/* 清除信息 */
			cateApiResponse.clearInfo();
		}
		/* 保存数据 */
		request.setAttribute("cateList", cateApiResponse.toJSON());
		return "/head/lawEnf/caseInsert";
	}
	
	/**
	 * 添加案件提交操作
	 * @return
	 */
	@RequestMapping("/caseInsertSubmit")
	public String caseInsertSubmit(HttpServletRequest request, String pubTimeStr , ACase case1, Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--caseInsertSubmit--");
		/* 当前用户 */
		AUsers users = (AUsers) this.findObjfromSession(request, "users");
		/* 设置用户Id */
		case1.setUsersId(users.getId() ) ;
		
		/* 为对象赋值 */
		case1.setPubTime(new Date());
		case1.setCreateTime(new Date());
		case1.setUpdateTime(new Date());
		/* 保存结果 */
		ApiResponse response = this.lawEnfDbService.saveOneCaseService(case1);
		ConstatFinalUtil.SYS_LOGGER.info("--案件添加返回结果:{}--",response.toJSON());
		request.setAttribute("response", response.toJSON());
		return  this.approvalInsert(request,this.cleanInfoFlag, model);
	}
	
	/**
	 * 打开更新案件页面
	 * @return
	 */
	@RequestMapping("/caseUpdate")
	public String caseUpdate(HttpServletRequest request,String id,String updateFlag,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--caseUpdate--");
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ACase> apiResponse = this.lawEnfDbService.findOneCaseService(condMap);
		if(updateFlag == null || "".equalsIgnoreCase(updateFlag))
		{
			/* 清除信息 */
			apiResponse.clearInfo();
		}
		/* 保留原来的信息 */
		JSONObject responseJSON = this.souResponse(request, apiResponse.toJSON());
		request.setAttribute("response", responseJSON);
		/* 存储request */
		
		/* 准备查询条件 */
		condMap.clear();
		condMap.put("cateType", ACateEnum.CATETYPE_APPROVAL.getStatus() + "");
		condMap.put("status", ACateEnum.STATUS_ENABLE.getStatus() + "");
		/* 查询所有的数据 */
		ApiResponse<ACate> cateApiResponse = this.lawEnfDbService.findCondListCateService(null, condMap);
		if(updateFlag == null || "".equalsIgnoreCase(updateFlag))
		{
			/* 清除信息 */
			cateApiResponse.clearInfo();
		}
		/* 保存数据 */
		request.setAttribute("cateList", cateApiResponse.toJSON());
		
		String operType = request.getParameter("operType");
		if("draft".equalsIgnoreCase(operType))
		{
			return "/head/lawEnf/caseUpdate";
		}else if("audit".equalsIgnoreCase(operType))
		{
			return "/head/lawEnf/caseAuditUpdate";
		}
		return "/head/lawEnf/caseInfo";
	}
	
	/**
	 * 添加案件提交操作
	 * @return
	 */
	@RequestMapping("/caseUpdateSubmit")
	public String caseUpdateSubmit(HttpServletRequest request,String id,
			Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--caseUpdateSubmit--");
		/* 当前用户 */
		AUsers users = (AUsers) this.findObjfromSession(request, "users");
		
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 准备查询条件 */
		Map<String, Object> condMap = new HashMap<String, Object>();
		condMap.put("id", id);
		/* 查询数据库 */
		ApiResponse<ACase> response = this.lawEnfDbService.findOneCaseService(condMap);
		/* 获取java对象 */
		ACase case1 = response.getDataOneJava() ;
		
		String operType = request.getParameter("operType");
		
		boolean flag = false; 
		
		if("draft".equalsIgnoreCase(operType))
		{
			/* 接收参数 */
			String name = request.getParameter("name");
			String content = request.getParameter("content");
			String appType = request.getParameter("appType");
			String status = request.getParameter("status");
			
			/* 设置属性 */
			case1.setName(name);
			case1.setAppType(Byte.valueOf(appType));
			case1.setContent(content);
			case1.setStatus(Byte.valueOf(status));
			
			if(case1.getUsersId() == users.getId())
			{
				flag = true ; 
			}else
			{
				/* 草稿状态必须本人修改 */
				apiResponse.setCode(ApiResponseEnum.INFO_SELF_OPER.getStatus());
				apiResponse.setInfo(ConstatFinalUtil.INFO_JSON.getString(apiResponse.getCode() + ""), Collections.EMPTY_MAP);
				
				request.setAttribute("response", apiResponse.toJSON());
			}
		}else if("audit".equalsIgnoreCase(operType))
		{
			/* 审核 */
			/* 接收参数 */
			String status = request.getParameter("status");
			String note = request.getParameter("note");
			
			/* 设置管理员 */
			if(ConstatFinalUtil.POSITION_DPART_LEADER.equalsIgnoreCase(users.getPosition().getCode()))
			{
				/* 局领导 */
				case1.setDepUseId(users.getId());
				case1.setDepAdmNote(note);
				
				if("1".equalsIgnoreCase(status))
				{
					case1.setStatus(ACaseEnum.STATUS_AUDIT_DEPART.getStatus());
				}
			}else if(ConstatFinalUtil.POSITION_BUREAU_LEADER.equalsIgnoreCase(users.getPosition().getCode()))
			{
				/* 部门领导 */
				case1.setDirUseId(users.getId());
				case1.setDirAdmNote(note);
				
				if("1".equalsIgnoreCase(status))
				{
					case1.setStatus(ACaseEnum.STATUS_AUDIT_BUREAU.getStatus());
				}
			}
			
			flag = true ; 
		}else if("finish".equalsIgnoreCase(operType))
		{
			if(users.getPosition().getCode().equalsIgnoreCase(ConstatFinalUtil.POSITION_BUREAU_LEADER))
			{
				/* 结案 */
				case1.setStatus(ACaseEnum.STATUS_AUDIT_FINISH.getStatus());
				flag = true ;
			}
		}
		if(flag)
		{
			case1.setUpdateTime(new Date());
			/* 数据库操作 */
			ApiResponse dbRes = this.lawEnfDbService.updateOneCaseService(case1);
			ConstatFinalUtil.SYS_LOGGER.info("--案件添加返回结果:{}--",dbRes.toJSON());
			request.setAttribute("response", dbRes.toJSON());
		}
		return caseUpdate(request, id, this.cleanInfoFlag, model);
	}
	
	/**
	 * 案件批量操作
	 * @return
	 */
	@RequestMapping(value = "/caseBatch" , produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String caseBatch(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--approvalBatch--");
		Map<String, Object> condMap = new HashMap<String, Object>();
		ApiResponse<Object> apiResponse = new ApiResponse<Object>();
		/* 从session中获取信息 */
		String[] ids = request.getParameterValues("ids");
		
		/* 操作类型 */
		String operType = request.getParameter("operType");
		if(ids != null)
		{
			int totalNum = ids.length ; 
			int succedNum = 0 ; 
			int failedNum = 0 ; 
			for (int i = 0; i < ids.length; i++)
			{
				String id = ids[i];
				if("status".equalsIgnoreCase(operType))
				{
					String status = request.getParameter("status");
					
					condMap.clear();
					condMap.put("id", id);
					ApiResponse<ACase> apiResponseDb = this.lawEnfDbService.findOneCaseService(condMap);
					ACase case1 = apiResponseDb.getDataOneJava();
					/* 设置状态 */
					case1.setStatus(Byte.valueOf(status));
					case1.setPubTime(new Date());
					
					ApiResponse<Object> apiResponseDb1 = this.lawEnfDbService.updateOneCaseService(case1);
					if(apiResponseDb1.getCode() == ApiResponseEnum.STATUS_SUCCESS.getStatus())
					{
						succedNum ++ ; 	
					}else
					{
						failedNum ++ ; 
					}
				}
			}
			
			StringBuffer sb = new StringBuffer();
			sb.append("总条数:" + totalNum + ";");
			sb.append("成功条数:" + succedNum + ";");
			sb.append("失败条数:" + failedNum + ";");
			apiResponse.setCode(ApiResponseEnum.STATUS_SUCCESS.getStatus());
			apiResponse.setInfo(sb.toString(), Collections.EMPTY_MAP);
		}
		return apiResponse.toJSON().toJSONString();
	}
	/*====案件表结束====*/
	
	/*====历史表开始====*/
	/**
	 * 申请单列表页面
	 * @return
	 */
	@RequestMapping("/historyList")
	public String historyList(HttpServletRequest request,Model model)
	{
		ConstatFinalUtil.SYS_LOGGER.info("--historyList--");
		/* 当前用户 */
		AUsers users = (AUsers) this.findObjfromSession(request, "users");
		/* 分页信息 */
		PageInfoUtil pageInfoUtil = this.proccedPageInfo(request);
		/* 搜索条件,生成公共的搜索条件 */
		Map<String, Object> condMap = this.proccedSearch(request);
		/*---- 额外增加的新条件 ----*/
		/*---- hisType ----*/
		String hisType = request.getParameter("hisType");
		if(hisType == null)
		{
			hisType = "";
		}
		condMap.put("hisType", hisType);
		request.setAttribute("hisType", hisType);
		
		/*---- hisType ----*/
		String relaId = request.getParameter("relaId");
		if(relaId == null)
		{
			relaId = "";
		}
		condMap.put("relaId", relaId);
		request.setAttribute("relaId", relaId);
		/* 查询数据库
		 * 所有的数据以JSON的形式返回
		 *  */
		ApiResponse<AHistory> apiResponse = this.lawEnfDbService.findCondListHistoryService(pageInfoUtil, condMap);
		/* 清除提示信息 */
		apiResponse.clearInfo();
		/* 将结果存储到Request中 */
		request.setAttribute("response", apiResponse.toJSON());
		return "/head/lawEnf/historyList";
	}
	/*====历史表结束====*/
}
